package com.example.controller;

import cn.hutool.json.JSONUtil;
import com.example.common.HttpStatusEnum;
import com.example.entity.ResponseData;
import com.example.pojo.Diagnosis;
import com.example.service.DiagnosisService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.List;

/**
 * 诊断信息表(Diagnosis)表控制层
 *
 * @email: pengyujun53@163.com
 * @author: peng_YuJun
 * @date: 2024/01/17
 * @time: 23:13
 */
@RestController
@RequestMapping("diagnosis")
@Api(tags = "Diagnosis信息请求类")
public class DiagnosisController {
    /**
     * 服务对象 
     */
    @Resource
    private DiagnosisService diagnosisService;

    /**
     * 分页查询
     * @param currentPage
     * @param pageSize
     * @param diagnosis 筛选条件
     * @return 查询结果
     */
    @ApiOperation("分页查询")
    @GetMapping("getPage")
    public ResponseData getPage(Integer currentPage, Integer pageSize, Diagnosis diagnosis) {
        if (currentPage == null || pageSize == null){
            return new ResponseData(HttpStatusEnum.BAD_REQUEST.getCode(), HttpStatusEnum.BAD_REQUEST.getMessage());
        }
        return diagnosisService.getByPage(currentPage, pageSize, diagnosis);
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @ApiOperation("根据ID查询信息")
    @GetMapping("findById")
    public ResponseData findById(Long id) {
        if (id == null){
            return new ResponseData(HttpStatusEnum.BAD_REQUEST.getCode(),HttpStatusEnum.BAD_REQUEST.getMessage());
        }
        return diagnosisService.findById(id);
    }

    /**
     * 新增数据
     *
     * @param  diagnosis 实体
     * @return 新增结果
     */
    @ApiOperation("增加")
    @PostMapping("add")
    public ResponseData add(Diagnosis diagnosis) {
        if(diagnosis == null){
            return new ResponseData(HttpStatusEnum.BAD_REQUEST.getCode(), HttpStatusEnum.BAD_REQUEST.getMessage());
        }
        return diagnosisService.add(diagnosis);
    }

    /**
     * 更新数据
     *
     * @param diagnosis 实体
     * @return 更新结果
     */
    @ApiOperation("更新")
    @PostMapping("update")
    public ResponseData update(Diagnosis diagnosis) {
        if(diagnosis == null || diagnosis.getId() == null){
            return new ResponseData(HttpStatusEnum.BAD_REQUEST.getCode(), HttpStatusEnum.BAD_REQUEST.getMessage());
        }
        return diagnosisService.update(diagnosis);
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 
     */
    @ApiOperation("删除")
    @PostMapping("delete")
    public ResponseData delete(Long id) {
        if (id == null){
            return new ResponseData(HttpStatusEnum.BAD_REQUEST.getCode(), HttpStatusEnum.BAD_REQUEST.getMessage());
        }
        return diagnosisService.delete(id);
    }

    /**
     * 批量删除
     * @param ids
     * @return
     */
    @ApiOperation("批量删除")
    @PostMapping("deleteBatch")
    public ResponseData deleteBatch(String ids){
        List<Long> idList = JSONUtil.toList(ids, Long.class);
        if (idList == null || idList.size()<=0){
            return new ResponseData(HttpStatusEnum.BAD_REQUEST.getCode(), HttpStatusEnum.BAD_REQUEST.getMessage());
        }
        return diagnosisService.deleteBatch(idList);
    }

    /**
     * 更新评论内容
     * @param id
     * @param evaluation
     * @return
     */
    @ApiOperation("更新评论内容")
    @PostMapping("updateEvaluation")
    public ResponseData updateEvaluation(Long id, String evaluation, Integer stars){
        if (id == null || !StringUtils.hasText(evaluation) || Arrays.asList(-1, null).contains(stars)){
            return new ResponseData(HttpStatusEnum.BAD_REQUEST.getCode(), HttpStatusEnum.BAD_REQUEST.getMessage());
        }
        return diagnosisService.updateEvaluation(id, evaluation, stars);
    }

    /**
     * 新增诊断和药单信息
     * @param symptoms
     * @param diagnosis
     * @param medicines
     * @param dosage
     * @param useway
     * @param price
     * @param aptId
     * @param sign
     * @return
     */
    @ApiOperation("新增诊断和药单信息")
    @PostMapping("makeDiagnosis")
    public ResponseData makeDiagnosis(String symptoms, String diagnosis, String medicines, String dosage, String useway,
                                      Double price, Long aptId, String sign){
        if (aptId == null){
            return new ResponseData(HttpStatusEnum.BAD_REQUEST.getCode(), HttpStatusEnum.BAD_REQUEST.getMessage());
        }
        if (!StringUtils.hasText(sign)){
            return new ResponseData(HttpStatusEnum.ERROR.getCode(), "请先上传签名图片");
        }
        return diagnosisService.makeDiagnosis(symptoms, diagnosis, medicines, dosage, useway, price, aptId, sign);
    }

    /**
     * 新增即时诊断和药单信息
     * @param symptoms
     * @param diagnosis
     * @param medicines
     * @param dosage
     * @param useway
     * @param price
     * @param drId
     * @Param stuCode
     * @param sign
     * @return
     */
    @ApiOperation("新增即时诊断和药单信息")
    @PostMapping("makeGoDiagnosis")
    public ResponseData makeGoDiagnosis(String symptoms, String diagnosis, String medicines, String dosage, String useway,
                                      Double price, Long drId, String stuCode, String sign){
        if (drId == null || !StringUtils.hasText(stuCode)){
            return new ResponseData(HttpStatusEnum.BAD_REQUEST.getCode(), HttpStatusEnum.BAD_REQUEST.getMessage());
        }
        if (!StringUtils.hasText(sign)){
            return new ResponseData(HttpStatusEnum.ERROR.getCode(), "请先上传签名图片");
        }
        return diagnosisService.makeGoDiagnosis(symptoms, diagnosis, medicines, dosage, useway, price, drId, stuCode, sign);
    }

    /**
     * 根据病患id查询记录
     * @param ptId
     * @return
     */
    @ApiOperation("根据病患id查询记录")
    @GetMapping("findByPtId")
    public ResponseData findByPtId(Long ptId){
        if (ptId == null) {
            return new ResponseData(HttpStatusEnum.BAD_REQUEST.getCode(), HttpStatusEnum.BAD_REQUEST.getMessage());
        }
        return diagnosisService.findByPtId(ptId);
    }

    /**
     * 根据医生id查询记录
     * @param drId
     * @return
     */
    @ApiOperation("根据医生id查询记录")
    @GetMapping("findByDrId")
    public ResponseData findByDrId(Long drId){
        if (drId == null) {
            return new ResponseData(HttpStatusEnum.BAD_REQUEST.getCode(), HttpStatusEnum.BAD_REQUEST.getMessage());
        }
        return diagnosisService.findByDrId(drId);
    }

    /**
     * 计算就诊频率
     * @return
     */
    @ApiOperation("计算就诊频率")
    @GetMapping("countDiagnosisFreq")
    public ResponseData countDiagnosisFreq(){
        return diagnosisService.countDiagnosisFreq();
    }

    /**
     * 计算确诊频率
     * @return
     */
    @ApiOperation("计算确诊频率")
    @GetMapping("countDiseaseFreq")
    public ResponseData countDiseaseFreq(){
        return diagnosisService.countDiseaseFreq();
    }

    /**
     * 统计病历数
     * @return
     */
    @ApiOperation("统计病历数")
    @GetMapping("countAll")
    public ResponseData countAll(){
        return diagnosisService.countAll();
    }

    /**
     * 统计不同时间段就诊数
     * @return
     */
    @ApiOperation("统计不同时间段就诊数")
    @GetMapping("countPeriod")
    public ResponseData countPeriod(){
        return diagnosisService.countPeriod();
    }

    /**
     * 统计不同科室就诊数
     * @return
     */
    @ApiOperation("统计不同科室就诊数")
    @GetMapping("countEntVisits")
    public ResponseData countEntVisits(){
        return diagnosisService.countEntVisits();
    }

    /**
     * 统计满意度
     * @return
     */
    @ApiOperation("统计满意度数")
    @GetMapping("countSatisfyDegree")
    public ResponseData countSatisfyDegree(){
        return diagnosisService.countSatisfyDegree();
    }

    /**
     * 统计词云
     * @return
     */
    @ApiOperation("统计词云")
    @GetMapping("countWordCloud")
    public ResponseData countWordCloud(){
        return diagnosisService.countWordCloud();
    }
}

